from flask import Flask, request
from flask_restplus import Resource, Api, Namespace, fields

ns = Namespace("fields", description="Fields描述和使用")
parser = ns.parser()


@ns.route("/fields")
class FieldsTest(Resource):
    EventReportRequest = ns.model('EventReportRequest', {
        'name': fields.String(required=True, description="姓名", example='Adair'),
        'age': fields.Integer(required=True, description="年龄", example='25'),
        'hobby': fields.List(fields.String, required=True, description="爱好", example=['ping-pong', 'ball', 'os-game'])
    })

    @ns.expect(EventReportRequest)
    @ns.doc(parser=parser)
    def post(self):
        args = parser.parse_args()
        payload = ns.payload
        name = payload['hobby']
        hobby = []
        for str in name:
            result = str
        return result

    @ns.doc(parser=parser)
    def put(self):
        return "put"
